#include "DataStructure/Input/Constraint/RBARData.h"

#include "DataStructure/Common/Validation.h"
#include "DataStructure/Input/Solver/DOFDirections.h"

using namespace SG::DataStructure;

/**
 * @brief 获取主自由度集1
 *
 * 返回主自由度集1的引用。
 *
 * @return 主自由度集1的引用
 */
SG::DataStructure::FEM::DofSet FEM::RBARData::GetMasterDof1 () const
{
    return Int2VDofSet (m_masterDof1);
}
void FEM::RBARData::SetMasterDof1 (const SG::DataStructure::FEM::DofSet& dofs)
{
    m_masterDof1 = DofSet2Int (dofs);
}

/**
 * @brief 获取主自由度集合2
 *
 * 返回一个主自由度集合2的引用。
 *
 * @return 主自由度集合2的引用
 */
SG::DataStructure::FEM::DofSet FEM::RBARData::GetMasterDof2 () const
{
    return Int2VDofSet (m_masterDof2);
}
void FEM::RBARData::SetMasterDof2 (const SG::DataStructure::FEM::DofSet& dofs)
{
    m_masterDof2 = DofSet2Int (dofs);
}

/**
 * @brief 获取从属自由度集合1
 *
 * 返回从属自由度集合1的实例。
 *
 * @return 从属自由度集合1的实例
 */
SG::DataStructure::FEM::DofSet FEM::RBARData::GetSlaveDof1 () const
{
    return Int2VDofSet (m_slaveDof1);
}
void FEM::RBARData::SetSlaveDof1 (const SG::DataStructure::FEM::DofSet& dofs)
{
    m_slaveDof1 = DofSet2Int (dofs);
}

/**
 * @brief 获取从节点自由度集合2
 *
 * 从内部数据结构中获取从节点的自由度集合2，并返回该集合。
 *
 * @return 从节点的自由度集合2
 */
SG::DataStructure::FEM::DofSet FEM::RBARData::GetSlaveDof2 () const
{
    return Int2VDofSet (m_slaveDof2);
}
void FEM::RBARData::SetSlaveDof2 (const SG::DataStructure::FEM::DofSet& dofs)
{
    m_slaveDof2 = DofSet2Int (dofs);
}

/// @brief 判断两个RBARData是否相等
/// @param a
/// @param b
/// @return
bool SG::DataStructure::FEM::operator== (const RBARData& a, const RBARData& b)
{
    if (a.m_id != b.m_id)
    {
        return false;
    }
    if (a.m_node1 != b.m_node1)
    {
        return false;
    }
    if (a.m_node2 != b.m_node2)
    {
        return false;
    }
    if (a.m_masterDof1 != b.m_masterDof1)
    {
        return false;
    }
    if (a.m_masterDof2 != b.m_masterDof2)
    {
        return false;
    }
    if (a.m_slaveDof1 != b.m_slaveDof1)
    {
        return false;
    }
    if (a.m_slaveDof2 != b.m_slaveDof2)
    {
        return false;
    }
    if (!SG::DataStructure::Common::isNear (a.m_alpha, b.m_alpha))
    {
        return false;
    }
    if (!SG::DataStructure::Common::isNear (a.m_refTemperature, b.m_refTemperature))
    {
        return false;
    }
    if (a.m_domainId != b.m_domainId)
    {
        return false;
    }
    return true;
}